package project.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import project.model.PrTestProject;

import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import approve.action.R;

public class ProjectListErrorAdapter extends BaseAdapter implements OnClickListener{
	Context context;
	List<PrTestProject> listTestPr;
	
	public ProjectListErrorAdapter(Context context,List<PrTestProject> listTest){
		this.context = context;
		this.listTestPr = listTest;
	}
	

	@Override
	public int getCount() {
		return listTestPr.size();
	}

	@Override
	public Object getItem(int arg0) {
		return listTestPr.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		final PrTestProject pr = listTestPr.get(arg0);
		String txtTitle = "";
		String txtTime = "";
		if(arg1==null){
			LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			arg1=inflater.inflate(R.layout.adaptererr, null);
		}
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
		TextView titleError=(TextView)arg1.findViewById(R.id.valtitleError);
//		txtTitle = pr.getTitle();
		txtTitle = pr.getTitleview();
		Spannable WordtoSpan = new SpannableString(txtTitle);        
		WordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor(pr.getColorText())), 0, txtTitle.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//		titleError.setText(pr.getTitle());
		titleError.setText(WordtoSpan);
		
		TextView datetime = (TextView)arg1.findViewById(R.id.datet);
//		txtTime = format.format(pr.getTime());
//		WordtoSpan = new SpannableString(txtTime);
//		WordtoSpan.setSpan(new ForegroundColorSpan(Color.parseColor(pr.getColorText())), 0, txtTime.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//		datetime.setText(WordtoSpan);
		
		datetime.setText(format.format(pr.getTime()) + "(" + pr.getEmployeeName() + ")");
		
		
		return arg1;
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		
	}

}
